package com.balabala.gym_consume.utils;

import com.balabala.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 * Author:zl
 * Date:2023/5/1 11:07
 */
@Slf4j
public class WebUtils {
    public static Result getResult(BindingResult bindingResult) {
        log.info("校验不通过...");
        //获取所有的错误信息
        List<ObjectError> errors = bindingResult.getAllErrors();
        StringBuilder sb=new StringBuilder();
        for(ObjectError objectError:errors){
            String message = objectError.getDefaultMessage();
            sb.append(message+",");
        }
        log.info("具体失败的原因:{}",sb.toString());
        return Result.fail(50000,sb.toString().substring(0,sb.toString().length()-1));
    }
}
